﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using Ue.Extensions;

namespace Ue.Components.VerificationCode
{
    public class VerifyCodeCharComponentOfFontStyle : IVerifyCodeCharComponents
    {
        #region IVerifyCodeCharComponents 成员

        public int Priority
        {
            get { return 10; }
        }

        public void Draw(ref Bitmap bitMap, ref Graphics graphics, ref Font font, ref Brush brush, char c)
        {
            font = new Font(font.FontFamily, font.Size, this.GetFontStyleByRandom(3));
        }

        public VerifyCodeStringComponent StringComponent { get; set; }

        #endregion

        private FontStyle GetFontStyleByRandom(int maxNumber)
        {
            if (maxNumber > 3)
            {
                maxNumber = 3;
            }

            var styles= new FontStyle[] { 
                    FontStyle.Bold, 
                    FontStyle.Italic, 
                    FontStyle.Underline }.GetRandom(0,3,false).ToArray();

            if (styles.Length == 0)
            {
                return FontStyle.Regular;
            }

            FontStyle style = styles[0];
            for (int i = 1; i < styles.Length; i++)
            {
                style |= styles[i];
            }

            return style;
        }
    }
}
